Fix case when source string consists of nothing but spaces. (Thanx, holux...)
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 9 Nov 2004 16:54:53 +0000 (16:54 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 9 Nov 2004 16:54:53 +0000 (16:54 +0000)
gpsbabel/mkshort.c

index 1c447244deacbd4b0b2d833524b3373e7056fa70..19ec3a51edb85b7441cc2406996b5a6a74b66c2e 100644 (file)
@@ -290,8 +290,12 @@ mkshort(void *h, const char *istring)
        ostring = nstring;
 
        /* Eliminate leading whitespace in all cases */
-       while (isspace(ostring[0])) {
-               memmove(&ostring[0], &ostring[1], strlen(ostring)-1);
+       while (ostring[0] && isspace(ostring[0])) {
+               /* If orig string has N bytes, we want to copy N-1 bytes
+                * of the string itself plus the string terminator (which 
+                * matters if the string consists of nothing but spaces) 
+                */
+               memmove(&ostring[0], &ostring[1], strlen(ostring));
        }
 
        if (!hdl->whitespaceok) {